﻿/**
*委托弹出表单
*/
Chenxin.UI.CommissionForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: 'service/trusthandler.ashx',
    id: 'commissionWin',
    renderTo: 'jqm_commission',
    title: '新增委托',
    winCls: 'comm',
    jqmWidth: 750,
	defBBtn:true,
    initFormValidator: function() {
        _this = this;
        //产权证号
        $("#cqzh").formValidator({ validatorgroup: this.id,
            onshow: "请输入产权证号！", onfocus: "请输入产权证号", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { leftempty: false, rightempty: false, emptyerror: "产权证号不能为空!" }, onerror: "产权证号不能为空!"
        });

        //委托编号
        $("#wtbh").formValidator({ validatorgroup: this.id,
            onshow: "请输入委托编号！", onfocus: "请输入委托编号", oncorrect: " "
        }).inputValidator({
            min: 1, onerror: "委托编号不能为空!"
        }).regexValidator({
            regexp: "num",
            datatype: "enum",
            onerror: "格式不正确"
        }).functionValidator({
            fun: function(val) {
                //返回结果
                $("#commission_Save").attr("disabled", "disabled");

                var bRet = false;

                if (_this.scope.currentModel) {
                    if (_this.scope.currentModel.EntrustCode == val) {
                        $("#commission_Save").removeAttr("disabled");
                        return true;
                    }
                }
                //存在验证
                $.ajax({
                    type: "post",
                    dataType: "json",
                    async: false,
                    url: _this.actionUrl,
                    data: { op: 'ExistsCode', EntrustCode: "wt" + val.padLeft(8, "0") },
                    success: function(jsonRet) {
                        //没有权限
                        if (jsonRet.success == "0") {
                            bRet = false
                            //时间过期
                        } else if (jsonRet.success == "-1") {
                            bRet = false;
                            //有权限
                        } else {
                            var strData = jsonRet.data;
                            //存在委托编号
                            if (strData == true) {
                                bRet = false;
                            } else {
                                bRet = true;
                            }
                        }
                        $("#commission_Save").removeAttr("disabled");
                    }
                });
                return bRet;
            },
            onerror: "该委托编号已存在"
        });

        //有效期from
        $("#fromdate").focus(function() {
            WdatePicker({ oncleared: function() { $(this).blur(); }, onpicked: function() { $(this).blur(); } })
        }).formValidator({ validatorgroup: this.id,
            onshow: "请输入开始日期！",
            onfocus: "请输入开始日期",
            oncorrect: " "
        }).inputValidator({
            empty: { leftempty: false, rightempty: false, emptyerror: "开始日期不能为空!" },
            type: "date",
            onerror: "开始日期不能为空"
        });

        //有效期to
        $("#todate").focus(function() {
            WdatePicker({ oncleared: function() { $(this).blur(); }, onpicked: function() { $(this).blur(); } })
        }).formValidator({ validatorgroup: this.id,
            onshow: "请输入结束日期！",
            onfocus: "请输入结束日期",
            oncorrect: " "
        }).inputValidator({
            empty: { leftempty: false, rightempty: false, emptyerror: "结束日期不能为空!" },
            type: "date",
            onerror: "结束日期不能为空"
        });

        //委托人
        $("#wtren").formValidator({ validatorgroup: this.id,
            onshow: "请输入姓名！", onfocus: "请输入姓名", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { emptyerror: "委托人不能为空!" }, onerror: "委托人不能为空!"
        });
        //联系地址
        $("#wtlxdz").formValidator({ validatorgroup: this.id,
            onshow: "请输入联系地址！", onfocus: "请输入联系地址", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { emptyerror: "联系地址不能为空!" }, onerror: "联系地址不能为空!"
        });

        //联系电话
        $("#lxdh").formValidator({ validatorgroup: this.id,
            onshow: "请输入电话！", onfocus: "请输入电话", oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                if ($("#lxdh").val() == "" && $("#wtsjhm").val() == "") {
                    return false;
                } else {
                    return true;
                }
            }, onerror: "请输入手机或电话！"
        });

        //手机号码
        $("#wtsjhm").formValidator({ validatorgroup: this.id,
            onshow: "请输入手机号！", onfocus: "请输入手机号", oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) { if (val == "") return true; return val.isMobile(); }, onerror: "请输入正确的手机号"
        }).functionValidator({
            fun: function(val, elem) {
                if ($("#lxdh").val() == "" && $("#wtsjhm").val() == "") {
                    return false;
                } else {
                    return true;
                }
            }, onerror: "请输入手机或电话！"
        });
        //邮政编码
        $("#wtyzbm").formValidator({ validatorgroup: this.id,
            onshow: "请输入邮政编码", onfocus: "请输入邮政编码", oncorrect: " "
        }).functionValidator({ //数字验证
            fun: function(val, elem) { return val.isNum(); }, onerror: "请输入数字"
        });
        //建筑面积
        $("#wtjzmj").formValidator({ validatorgroup: this.id,
            onshow: "请输入面积", onfocus: "请输入面积", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { leftempty: false, rightempty: false, emptyerror: "面积不能为空!" }, onerror: "面积不能为空!"
        }).functionValidator({ //数字验证
            fun: function(val, elem) {
                return val.isNum() && parseFloat(val) > 1;
            }, onerror: "请输入大于1的数字"
        });

        //房屋总价
        $("#wtfwzj").formValidator({ validatorgroup: this.id,
            onshow: "请输入价格", onfocus: "请输入价格", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { leftempty: false, rightempty: false, emptyerror: "房屋总价不能为空!" }, onerror: "房屋总价不能为空!"
        }).functionValidator({ //数字验证
            fun: function(val, elem) { return val.isNum(); }, onerror: "请输入数字"
        });

        //租赁价格
        $("#wtzljg").formValidator({ validatorgroup: this.id,
            onshow: "请输入价格！", onfocus: "请输入价格", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { leftempty: false, rightempty: false, emptyerror: "租赁价格不能为空!" }, onerror: "租赁价格不能为空!"
        }).functionValidator({ //数字验证
            fun: function(val, elem) {
                return val.isNum();
            }, onerror: "请输入数字"
        });
        // $("#wtfwzj").unFormValidator(true);
        // $("#wtzljg").unFormValidator(false);

        // 租赁价格
        $("#wtzljg").unFormValidator(true);
        //建筑面积
        $("#wtjzmj").unFormValidator(false);
        //房屋总价
        $("#wtfwzj").unFormValidator(false);
    },
    createForm: function() {
        return Chenxin.FormCommon.houseCommissionForm('commission');
    },
    initEvent: function() {
        var _this = this;
        $('#commission_Save').live('click', function() {
            _this.save();
        });
        $('#commission_Cancle').live('click', function() {
            _this.hide();
        });
        /**********************事件：委托编号失去焦点****************/
        $("#wtbh").blur(function() {
            if (this.value != "") {
                this.value = this.value.padLeft(8, "0");
            }
        });
        /**********************事件：委托类型点击事件****************/
        $("input[name='EntrustType']").click(function() {
            var strType = this.value;
            switch (strType) {
                case "10":
                    //_this.findByName("TotalPrice").unFormValidator(true);
                    // _this.findByName("RentPrice").unFormValidator(false);
                    // 租赁价格
                    $("#wtzljg").unFormValidator(true);
                    //建筑面积
                    $("#wtjzmj").unFormValidator(false);
                    //房屋总价
                    $("#wtfwzj").unFormValidator(false);
                    break;
                case "20":
                    //_this.findByName("TotalPrice").unFormValidator(false);
                    //_this.findByName("RentPrice").unFormValidator(true);
                    // 租赁价格
                    $("#wtzljg").unFormValidator(false);
                    //建筑面积
                    $("#wtjzmj").unFormValidator(true);
                    //房屋总价
                    $("#wtfwzj").unFormValidator(true);
                    break;
                case "30":
                    // _this.findByName("TotalPrice").unFormValidator(false);
                    // _this.findByName("RentPrice").unFormValidator(false);
                    // 租赁价格
                    $("#wtzljg").unFormValidator(false);
                    //建筑面积
                    $("#wtjzmj").unFormValidator(false);
                    //房屋总价
                    $("#wtfwzj").unFormValidator(false);
                    break;
            }
        });
    },
    createComboList: function() {
        var region = new Chenxin.UI.ParameterCombo({
            name: 'District',
            containerId: '#commission_District',
            inModelType: 'txt',
            key: 'System.Region',
            required: true
        });
        var contactType = new Chenxin.UI.ParameterCombo({
            name: 'ContactType',
            containerId: '#commission_ContactType',
            inModelType: 'txt',
            key: 'Contact.Type'
        });
        var nationality = new Chenxin.UI.Combo({
            containerId: '#commission_Nationality',
            name: 'Nationality',
            autoLoad: false,
            inModelType: 'txt',
            items: comboCommon.country
        });
        var _this = this;
//        //委托部门
//        var cboEmpDepartId = new Chenxin.UI.DepartTreeCombo({
//            containerId: '#txtEmployeeId',
//            textBoxId: 'txtEmployeeId',
//            name: 'EmpDepartId',
//            inModelType: 'all',
//            txtModelName: 'EmpDepart',
//            required: true,
//            afterSetValue: function(val, txt) {
//                if (val != this.defVal) {
//                    cboEmployeeId.loadUser(val)
//                }
//            },
//            onSelected: function() {
//                if (this.getValue() != this.defVal) {
//                    cboEmployeeId.loadUser(this.getValue());
//                }
//            }
//        });
//        
//        //委托人
//        var cboEmployeeId = new Chenxin.UI.RichModelTreeCombo({
//            containerId: '#txtEmployeeId',
//            textBoxId: 'txtEmployeeId',
//            inModelType: 'all',
//            txtModelName: 'Employee',
//            required: true,
//            singleSelect: true,
//            name: 'EmployeeId'
//        });

//        return [region, contactType, nationality, cboEmpDepartId, cboEmployeeId];
//    },
//    saveSucc: function() {
//        if (this.grid) {
//            this.reloadGrid();
//        }
//    },
//    initComponent: function() {
//        Chenxin.UI.CommissionForm.superclass.initComponent.call(this);
//    }
//});

///**
//*@description 房屋委托
//*@comboIdPrefix DIV下拉框和提交按钮前缀
//*/
//Chenxin.FormCommon.houseCommissionForm=function(comboIdPrefix) {
//    return '<table class="tbl_f jqTabWh"><tbody><tr style="height:30px;display:none"><th style="width:60px;">委托性质：</th><td colspan="3"><input type="radio" name="Type" checked="checked" value="10"/>一般委托</tr><tr style="height:30px"><th style="width:60px;">委托门店：</th><td style="width:290px;"><input type=text id="txtEmpDepartId" class="inputbox_n fl" style="width:151px" /></td><th style="width:75px;">委托业务员：</th><td style="width:290px;"><input style="width: 120px;" type="text" class="inputbox_n" id="txtEmployeeId" /></td></tr><tr style="height:30px"><th style="width:60px;">房源编号：</th><td colspan="3"><input style="width:496px;" name="HouseCode" type="text" readonly="readonly"  class="inputbox_n"/></td></tr><tr><th style="width:75px;">房源地址：</th><td colspan="3"><input name="HouseAddress" type="text" readonly="readonly" style="width:496px;" class="inputbox_n"/></td>  </tr>  <tr style="height:30px"><th style="width:60px;">委托编号：</th><td><div style="float:left;"><input type="text" style="width:20px;" value="wt" readonly="readonly" class="inputbox_n" /><input name="EntrustCode" type="text" maxlength="8" style="width:95px;" value="" class="inputbox_n PNUM" id="wtbh" /></div><div style="float:left" id="wtbhTip" /></td><th style="width:75px;">产权证号：</th><td><div style="float:left;"><input name="PropertyCode" type="text" maxlength="20"  style="width: 120px;" value="" class="inputbox_n" id="cqzh" /></div><div style="float:left" id="cqzhTip" /></td>  </tr>  <tr style="height:30px"><th style="width:60px;">有效期：</th><td><div style="float:left"><input type="text" name="StartTime"  readonly="readonly"  style="width: 120px;" value="" class="inputbox_n" id="fromdate" /></div><div style="float:left" id="fromdateTip" /></td><th style="width:75px;">到</th><td><div style="float:left"><input name="EndTime" readonly="readonly"  type="text" style="width: 120px;" value="" class="inputbox_n" id="todate" /></div><div style="float:left" id="todateTip" /></td>  </tr>  <tr style="height:30px"><th style="width:60px;">委托人：</th><td><div style="float:left"><input type="hidden" name="CustomerId" /><input type="text" name="CustomerName"  maxlength="10" style="width: 120px;" value="" class="inputbox_n" id="wtren" /></div><div style="float:left" id="wtrenTip" /></td><th style="width:75px;">联系地址：</th><td><div style="float:left;"><input type="text" name="CustomerAddress" maxlength="25" style="width: 120px;" value="" class="inputbox_n" id="wtlxdz" /></div> <div style="float:left" id="wtlxdzTip" /></td>  </tr>   <tr style="height:30px"><th style="width:60px;">联系电话：</th><td  style="width: 300px;" ><div style="float:left"><input type="text" name="Phone" maxlength="50" style="width: 160px;" value="" class="inputbox_n" id="lxdh" /></div><div style="float:left" id="lxdhTip" /></td><th style="width:75px;">手机号码：</th><td><div style="float:left"><input type="text" name="Mobile"  maxlength="20" style="width: 120px;" value="" class="inputbox_n" id="wtsjhm" /></div><div style="float:left" id="wtsjhmTip" /></td>  </tr><tr style="height:30px"><th style="width:60px;">联系方式：</th><td> <div id="' + comboIdPrefix + '_ContactType" style="z-index:801; margin-right: 5px;" class="SelectWrapSingle"></div><input type="hidden" id="HidWtlxfs" value="0" /></td><th style="width:75px;">国籍：</th><td><div id="' + comboIdPrefix + '_Nationality" style="z-index:901; margin-right: 5px;" class="SelectWrapSingle"></div></td>  </tr><tr style="height:30px"><th style="width:60px;">邮政编码：</th><td><div style="float:left"><input name="AddressZip" type="text"  maxlength="6"  style="width: 120px;" value="" class="inputbox_n" id="wtyzbm" /></div><div style="float:left" id="wtyzbmTip" /></td><th style="width:75px;">区域：</th><td><div id="' + comboIdPrefix + '_District" style="z-index:900; margin-right: 5px;" class="SelectWrapSingle"></div></td>  </tr>  <tr style="height:30px"><th style="width:60px;">委托类型：</th><td><input type="radio" name="EntrustType"  checked="checked"  id= "entrustype2" value="10" />出售<input type="radio" name="EntrustType" id= "entrustype1"  value="20" />出租<input type="radio" name="EntrustType"  id= "entrustype3" value="30" />租售</td>  <th style="width:60px;">建筑面积：</th><td><div style="float:left"><input name="Area" onchange="setunitprice();" type="text" style="width: 120px;" maxlength="6"  value="" class="inputbox_n" id="wtjzmj" /></div><div style="float:left" id="wtjzmjTip" /></td></tr>   <tr style="height:30px"> <th id="housePriceName" style="width:75px;">房屋总价：</th><td><div style="float:left"><input name="TotalPrice" type="text" style="width: 120px;"  maxlength="13" value="" class="inputbox_n" id="wtfwzj" onchange="setunitprice();"/></div><div style="float:left" id="wtfwzjTip" /></td><th style="width:60px;">租赁价格：</th><td>   <div style="float:left"><input name="RentPrice" type="text"  maxlength="6" style="width: 120px;" value="" class="inputbox_n" id="wtzljg" /></div>   <div style="float:left" id="wtzljgTip" /></td> </tr>  <tr style="height:30px;display:none"> <th style="width:75px;">房屋单价：</th><td colspan=3> <div style="float:left"><input name="UnitPrice" type="text"  disabled="disabled" style="width: 120px;" value="" class="inputbox_n" id="wtfwdj" /></div><div style="float:left;line-height:25px; padding-left:5px;" id="Div8">元</div></td> </tr><tr style="height:30px"><th style="width:60px;">备注：</th><td colspan="3"><div style="float:left"><textarea name="Memo" onkeypress="if (this.value.length>=200){event.returnValue=false}"  onchange="if (this.value.length>=200){this.value=this.value.substr(0, 200)}"  id="wt_remarks" cols="100" rows="3" class="textarea_n" style="width:590px; height: 60px; padding:5px; overflow:hidden"></textarea></div><div style="float:left; text-align:center; vertical-align:middle" id="wt_remarksTip" /></td>  </tr></tbody></table>';
//};
        this.empDepartId = new Chenxin.UI.Combo({
            actionUrl: 'service/structhandler.ashx?op=getcontroldeparts',
            containerId: '#commission_EmpDepartId',
            typeModel: 'new',
            name: 'EmpDepartId',
            autoLoad: true,

            required: true,
            hasPage: true,
            pageSize: 8,
			onSelected:function(){
				if(this.getValue()==this.defVal){
					
				}else{
					_this.employeeId.loadUser(this.getValue());
				}
			}

        });
        this.employeeId = new Chenxin.UI.RichModelTreeCombo({
            textBoxId: 'commission_EmployeeId',







            name: 'EmployeeId'
        });
        return [region, contactType, nationality, this.empDepartId, this.employeeId];

    },
    saveSucc: function() {
        if (this.grid) {
            this.reloadGrid();
        }
    },
    initComponent: function() {
        Chenxin.UI.CommissionForm.superclass.initComponent.call(this);
    }
});

/**
*@description 房屋委托
*@comboIdPrefix DIV下拉框和提交按钮前缀
*/
Chenxin.FormCommon.houseCommissionForm=function(comboIdPrefix) {
    return '<table class="tbl_f jqTabWh"><tbody><tr style="height:30px;display:none"><th style="width:60px;">委托性质：</th><td colspan="3"><input type="radio" name="Type" checked="checked" value="10"/>一般委托</tr><tr style="height:30px"><th style="width:60px;">委托门店：</th><td style="width:290px;"><div id="' + comboIdPrefix + '_EmpDepartId" style="z-index: 904; margin-right: 5px;" class="SelectWrapSingle"></div></td><th style="width:75px;">委托业务员：</th><td style="width:290px;"> <input style="width: 120px;" type="text" class="inputbox_n" id="' + comboIdPrefix + '_EmployeeId" /></div></td>  </tr>  <tr style="height:30px"><th style="width:60px;">房源编号：</th><td colspan="3"><input style="width:496px;" name="HouseCode" type="text" readonly="readonly"  class="inputbox_n"/></td></tr><tr><th style="width:75px;">房源地址：</th><td colspan="3"><input name="HouseAddress" type="text" readonly="readonly" style="width:496px;" class="inputbox_n"/></td>  </tr>  <tr style="height:30px"><th style="width:60px;">委托编号：</th><td><div style="float:left;"><input type="text" style="width:20px;" value="wt" readonly="readonly" class="inputbox_n" /><input name="EntrustCode" type="text" maxlength="8" style="width:95px;" value="" class="inputbox_n PNUM" id="wtbh" /></div><div style="float:left" id="wtbhTip" /></td><th style="width:75px;">产权证号：</th><td><div style="float:left;"><input name="PropertyCode" type="text" maxlength="20"  style="width: 120px;" value="" class="inputbox_n" id="cqzh" /></div><div style="float:left" id="cqzhTip" /></td>  </tr>  <tr style="height:30px"><th style="width:60px;">有效期：</th><td><div style="float:left"><input type="text" name="StartTime"  readonly="readonly"  style="width: 120px;" value="" class="inputbox_n" id="fromdate" /></div><div style="float:left" id="fromdateTip" /></td><th style="width:75px;">到</th><td><div style="float:left"><input name="EndTime" readonly="readonly"  type="text" style="width: 120px;" value="" class="inputbox_n" id="todate" /></div><div style="float:left" id="todateTip" /></td>  </tr>  <tr style="height:30px"><th style="width:60px;">委托人：</th><td><div style="float:left"><input type="hidden" name="CustomerId" /><input type="text" name="CustomerName"  maxlength="10" style="width: 120px;" value="" class="inputbox_n" id="wtren" /></div><div style="float:left" id="wtrenTip" /></td><th style="width:75px;">联系地址：</th><td><div style="float:left;"><input type="text" name="CustomerAddress" maxlength="25" style="width: 120px;" value="" class="inputbox_n" id="wtlxdz" /></div> <div style="float:left" id="wtlxdzTip" /></td>  </tr>   <tr style="height:30px"><th style="width:60px;">联系电话：</th><td  style="width: 300px;" ><div style="float:left"><input type="text" name="Phone" maxlength="50" style="width: 160px;" value="" class="inputbox_n" id="lxdh" /></div><div style="float:left" id="lxdhTip" /></td><th style="width:75px;">手机号码：</th><td><div style="float:left"><input type="text" name="Mobile"  maxlength="20" style="width: 120px;" value="" class="inputbox_n" id="wtsjhm" /></div><div style="float:left" id="wtsjhmTip" /></td>  </tr><tr style="height:30px"><th style="width:60px;">联系方式：</th><td> <div id="' + comboIdPrefix + '_ContactType" style="z-index:801; margin-right: 5px;" class="SelectWrapSingle"></div><input type="hidden" id="HidWtlxfs" value="0" /></td><th style="width:75px;">国籍：</th><td><div id="' + comboIdPrefix + '_Nationality" style="z-index:901; margin-right: 5px;" class="SelectWrapSingle"></div></td>  </tr><tr style="height:30px"><th style="width:60px;">邮政编码：</th><td><div style="float:left"><input name="AddressZip" type="text"  maxlength="6"  style="width: 120px;" value="" class="inputbox_n" id="wtyzbm" /></div><div style="float:left" id="wtyzbmTip" /></td><th style="width:75px;">区域：</th><td><div id="' + comboIdPrefix + '_District" style="z-index:900; margin-right: 5px;" class="SelectWrapSingle"></div></td>  </tr>  <tr style="height:30px"><th style="width:60px;">委托类型：</th><td><input type="radio" name="EntrustType"  checked="checked"  id= "entrustype2" value="10" />出售<input type="radio" name="EntrustType" id= "entrustype1"  value="20" />出租<input type="radio" name="EntrustType"  id= "entrustype3" value="30" />租售</td>  <th style="width:60px;">建筑面积：</th><td><div style="float:left"><input name="Area" onchange="setunitprice();" type="text" style="width: 120px;" maxlength="6"  value="" class="inputbox_n" id="wtjzmj" /></div><div style="float:left" id="wtjzmjTip" /></td></tr>   <tr style="height:30px"> <th id="housePriceName" style="width:75px;">房屋总价：</th><td><div style="float:left"><input name="TotalPrice" type="text" style="width: 120px;"  maxlength="13" value="" class="inputbox_n" id="wtfwzj" onchange="setunitprice();"/></div><div style="float:left" id="wtfwzjTip" /></td><th style="width:60px;">租赁价格：</th><td>   <div style="float:left"><input name="RentPrice" type="text"  maxlength="6" style="width: 120px;" value="" class="inputbox_n" id="wtzljg" /></div>   <div style="float:left" id="wtzljgTip" /></td> </tr>  <tr style="height:30px;display:none"> <th style="width:75px;">房屋单价：</th><td colspan=3> <div style="float:left"><input name="UnitPrice" type="text"  disabled="disabled" style="width: 120px;" value="" class="inputbox_n" id="wtfwdj" /></div><div style="float:left;line-height:25px; padding-left:5px;" id="Div8">元</div></td> </tr><tr style="height:30px"><th style="width:60px;">备注：</th><td colspan="3"><div style="float:left"><textarea name="Memo" onkeypress="if (this.value.length>=200){event.returnValue=false}"  onchange="if (this.value.length>=200){this.value=this.value.substr(0, 200)}"  id="wt_remarks" cols="100" rows="3" class="textarea_n" style="width:590px; height: 60px; padding:5px; overflow:hidden"></textarea></div><div style="float:left; text-align:center; vertical-align:middle" id="wt_remarksTip" /></td>  </tr></tbody></table>';
};
